package simulacion.java;
// OOSimL v 1.1 File: car.java, Tue Jan 31 15:15:41 2012
 
import java.util.*; 
import psimjava.*; 
/** 
description
  The model of the car-wash system
  OOSIMl version,  J Garrido. Updated Jan 2012

  This class defines behavior of car objects
  After a car object is created it joins the queue to wait for
  service. It it finds the server object idle, 
  it reactivates the server object.
*/
 public  class Car  extends psimjava.Process     {
static Scanner scan = new Scanner (System.in);
 private int  customerNum; 
  // customer number 
 private double  arrivalTime; 
  // arrival time of customer 
 private double  service_dur; 
  // cust service interval 
 // 
 public Car( String  cname, double  dur) { 
super(cname); 
customerNum =  SimulacionJava.num_arrived;
arrivalTime = StaticSync.get_clock();
service_dur =  dur;
System.out.println(cname+ 
" arrives at time "+ 
arrivalTime);
 } // end initializer 
 // 
 public double  get_arrivalT(   ) { 
return arrivalTime; 
 }  // end get_arrivalT 
 // 
 public double  get_serv_dur(   ) { 
return service_dur; 
 }  // end get_serv_dur 
 // 
 public void  Main_body(   ) { 
 double  simclock; 
  String  pname; 
  double  a; 
  // bogus 
 simclock = StaticSync.get_clock();
pname =  get_name();
System.out.println(pname+ 
" requests service at time "+ 
simclock);
 // check if there is still space available in the carwash shop 
 if ( !SimulacionJava.car_queue.full()) { 
 // queue not full 
System.out.println(pname+ 
" joins queue at time "+ 
simclock);
tracedisplay(pname+ 
" joins queue ");
SimulacionJava.car_queue.into(this );
 // enqueue this car 
 if ( SimulacionJava.wash_machine.idle()) { 
System.out.println("Activating server at time "+ 
simclock);
 reactivate(SimulacionJava.wash_machine);
 // call Thread.yield  
 } // endif 
 // 
 // to wait for service         
 deactivate(this);
 // service completed, do final computation 
 // customers serviced 
 SimulacionJava.num_serviced++;
 // total time in the system: custSojournTime 
 simclock = StaticSync.get_clock();
SimulacionJava.custSojournTime =  (SimulacionJava.custSojournTime) + (( (simclock) - (arrivalTime)) );
System.out.println(pname+ 
" terminates at "+ 
simclock);
  terminate();
 // terminates itself       
 }
 else {
 // queue full, abandon hope                                
 SimulacionJava.num_rejected++;
System.out.println(pname+ 
" rejected, queue full ");
tracedisplay(pname+ 
" rejected, queue full ");
  terminate();
 // terminate this object 
 } // endif 
 }  // end Main_body 
} // end class/interf Car 